package cn.zjj._01_sync_2;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * 生产者
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        //1.生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("sync2_producer_producer");
        //2.设置nameserver
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.创建并发送消息
        Message message = new Message("user","login","这是user标题下的login消息传递".getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        System.out.println(send);
        //5.关闭
        producer.shutdown();

    }

}
